package com.open.pokergames.biz.views.invite

import android.os.Bundle
import com.open.pokergames.biz.entity.MemberEntity
import com.open.pokergames.biz.views.invite.adapter.MemberListAdapter
import com.open.pokergames.comm.repository.entity.ResultInfo
import com.open.pokergames.comm.userCenter.UserSearchActivity
import com.sinothk.android.utils.XUtils
import kotlinx.android.synthetic.main.activity_load_recycle_view_load_tip_white_bg_for_search.*
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

class InviteInputActivity : UserSearchActivity() {

    private var groupId: String? = ""
    private var adapter: MemberListAdapter? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        groupId = intent.getStringExtra("groupId")
    }

    override fun retData() {
        if (adapter!!.data != null && adapter!!.data.size > 0) {
            adapter!!.data = null
        }
    }

    override fun setAdapter() {
        adapter = MemberListAdapter(this)
        adapter!!.setOnSuperListener(this)
        loadingRecyclerView.adapter = adapter
    }

    override fun setAdapterData(data: MutableList<MemberEntity>) {
        adapter!!.setData(data)
    }

    override fun updateAdapterData(data: MutableList<MemberEntity>) {
        adapter!!.updateData(data)
    }

    override fun onClick(position: Int, itemData: MemberEntity?, flag: String?) {

        when (flag) {
            "inviteTv" -> {
                showLoadingDialog("正在处理")
                viewModel!!.inviteAdd(groupId, itemData!!.account)
            }
        }

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public fun inviteAddBusCallback(result: ResultInfo<String>) {

        if ("inviteAdd" != result.eventType) {
            return
        }

        hideLoadingDialog()

        when (result.code) {
            ResultInfo.SUCCESS -> {
                XUtils.toast().show("邀请已发出")
                refreshData()
            }
            else -> {
                XUtils.toast().show(result.msg)
            }
        }
    }

}